package com.paper.tiger.easy.rpc.s.client.handler;

import com.paper.tiger.easy.rpc.core.kryo.KryoSerializer;
import com.paper.tiger.easy.rpc.s.client.common.Dove;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 编码,对数据进行编码
 */
@ChannelHandler.Sharable
public class KryoDoveEncoder extends MessageToByteEncoder<Dove> {


    @Override
    protected void encode(ChannelHandlerContext ctx, Dove msg, ByteBuf out) throws Exception {

        KryoSerializer.serialize(msg, out);
        ctx.flush();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
    {
       cause.printStackTrace();
    }
}
